home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / matmania.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  11KB  |  404 lines

  1. /***************************************************************************
  2.  
  3.     vidhrdw.c
  4.  
  5.     Functions to emulate the video hardware of the machine.
  6.  
  7.     There are only a few differences between the video hardware of Mysterious
  8.     Stones and Mat Mania. The tile bank select bit is different and the sprite
  9.     selection seems to be different as well. Additionally, the palette is stored
  10.     differently. I'm also not sure that the 2nd tile page is really used in
  11.     Mysterious Stones.
  12.  
  13. ***************************************************************************/
  14.  
  15. #include "driver.h"
  16. #include "vidhrdw/generic.h"
  17.  
  18.  
  19.  
  20. unsigned char *matmania_videoram2,*matmania_colorram2;
  21. size_t matmania_videoram2_size;
  22. unsigned char *matmania_videoram3,*matmania_colorram3;
  23. size_t matmania_videoram3_size;
  24. unsigned char *matmania_scroll;
  25. static struct osd_bitmap *tmpbitmap2;
  26. static unsigned char *dirtybuffer2;
  27.  
  28. unsigned char *matmania_pageselect;
  29.  
  30. /***************************************************************************
  31.  
  32.   Convert the color PROMs into a more useable format.
  33.  
  34.   Mat Mania is unusual in that it has both PROMs and RAM to control the
  35.   palette. PROMs are used for characters and background tiles, RAM for
  36.   sprites.
  37.   I don't know for sure how the PROMs are connected to the RGB output,
  38.   but it's probably the usual:
  39.  
  40.   bit 7 -- 220 ohm resistor  -- GREEN
  41.         -- 470 ohm resistor  -- GREEN
  42.         -- 1  kohm resistor  -- GREEN
  43.         -- 2.2kohm resistor  -- GREEN
  44.         -- 220 ohm resistor  -- RED
  45.         -- 470 ohm resistor  -- RED
  46.         -- 1  kohm resistor  -- RED
  47.   bit 0 -- 2.2kohm resistor  -- RED
  48.  
  49.   bit 3 -- 220 ohm resistor  -- BLUE
  50.         -- 470 ohm resistor  -- BLUE
  51.         -- 1  kohm resistor  -- BLUE
  52.   bit 0 -- 2.2kohm resistor  -- BLUE
  53.  
  54. ***************************************************************************/
  55. void matmania_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  56. {
  57.     int i;
  58.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  59.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  60.  
  61.  
  62.     for (i = 0;i < 64;i++)
  63.     {
  64.         int bit0,bit1,bit2,bit3;
  65.  
  66.  
  67.         bit0 = (color_prom[0] >> 0) & 0x01;
  68.         bit1 = (color_prom[0] >> 1) & 0x01;
  69.         bit2 = (color_prom[0] >> 2) & 0x01;
  70.         bit3 = (color_prom[0] >> 3) & 0x01;
  71.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  72.         bit0 = (color_prom[0] >> 4) & 0x01;
  73.         bit1 = (color_prom[0] >> 5) & 0x01;
  74.         bit2 = (color_prom[0] >> 6) & 0x01;
  75.         bit3 = (color_prom[0] >> 7) & 0x01;
  76.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  77.         bit0 = (color_prom[64] >> 0) & 0x01;
  78.         bit1 = (color_prom[64] >> 1) & 0x01;
  79.         bit2 = (color_prom[64] >> 2) & 0x01;
  80.         bit3 = (color_prom[64] >> 3) & 0x01;
  81.         *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  82.  
  83.         color_prom++;
  84.     }
  85. }
  86.  
  87.  
  88.  
  89. WRITE_HANDLER( matmania_paletteram_w )
  90. {
  91.     int bit0,bit1,bit2,bit3,val;
  92.     int r,g,b;
  93.     int offs2;
  94.  
  95.  
  96.     paletteram[offset] = data;
  97.     offs2 = offset & 0x0f;
  98.  
  99.     val = paletteram[offs2];
  100.     bit0 = (val >> 0) & 0x01;
  101.     bit1 = (val >> 1) & 0x01;
  102.     bit2 = (val >> 2) & 0x01;
  103.     bit3 = (val >> 3) & 0x01;
  104.     r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  105.  
  106.     val = paletteram[offs2 | 0x10];
  107.     bit0 = (val >> 0) & 0x01;
  108.     bit1 = (val >> 1) & 0x01;
  109.     bit2 = (val >> 2) & 0x01;
  110.     bit3 = (val >> 3) & 0x01;
  111.     g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  112.  
  113.     val = paletteram[offs2 | 0x20];
  114.     bit0 = (val >> 0) & 0x01;
  115.     bit1 = (val >> 1) & 0x01;
  116.     bit2 = (val >> 2) & 0x01;
  117.     bit3 = (val >> 3) & 0x01;
  118.     b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  119.  
  120.     palette_change_color(offs2 + 64,r,g,b);
  121. }
  122.  
  123.  
  124. /***************************************************************************
  125.  
  126.   Start the video hardware emulation.
  127.  
  128. ***************************************************************************/
  129. int matmania_vh_start(void)
  130. {
  131.     if ((dirtybuffer = malloc(videoram_size)) == 0)
  132.         return 1;
  133.     memset(dirtybuffer,1,videoram_size);
  134.  
  135.     if ((dirtybuffer2 = malloc(matmania_videoram3_size)) == 0)
  136.     {
  137.         free(dirtybuffer);
  138.         return 1;
  139.     }
  140.     memset(dirtybuffer2,1,matmania_videoram3_size);
  141.  
  142.     /* Mat Mania has a virtual screen twice as large as the visible screen */
  143.     if ((tmpbitmap = osd_create_bitmap(Machine->drv->screen_width,2* Machine->drv->screen_height)) == 0)
  144.     {
  145.         free(dirtybuffer);
  146.         free(dirtybuffer2);
  147.         return 1;
  148.     }
  149.  
  150.     /* Mat Mania has a virtual screen twice as large as the visible screen */
  151.     if ((tmpbitmap2 = osd_create_bitmap(Machine->drv->screen_width,2 * Machine->drv->screen_height)) == 0)
  152.     {
  153.         free(tmpbitmap);
  154.         free(dirtybuffer);
  155.         free(dirtybuffer2);
  156.         return 1;
  157.     }
  158.  
  159.     return 0;
  160. }
  161.  
  162.  
  163.  
  164. /***************************************************************************
  165.  
  166.   Stop the video hardware emulation.
  167.  
  168. ***************************************************************************/
  169. void matmania_vh_stop(void)
  170. {
  171.     free(dirtybuffer);
  172.     free(dirtybuffer2);
  173.     osd_free_bitmap(tmpbitmap);
  174.     osd_free_bitmap(tmpbitmap2);
  175. }
  176.  
  177.  
  178. WRITE_HANDLER( matmania_videoram3_w )
  179. {
  180.     if (matmania_videoram3[offset] != data)
  181.     {
  182.         dirtybuffer2[offset] = 1;
  183.  
  184.         matmania_videoram3[offset] = data;
  185.     }
  186. }
  187.  
  188.  
  189.  
  190. WRITE_HANDLER( matmania_colorram3_w )
  191. {
  192.     if (matmania_colorram3[offset] != data)
  193.     {
  194.         dirtybuffer2[offset] = 1;
  195.  
  196.         matmania_colorram3[offset] = data;
  197.     }
  198. }
  199.  
  200.  
  201. void matmania_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  202. {
  203.     int offs;
  204.  
  205.  
  206.     if (palette_recalc())
  207.     {
  208.         memset(dirtybuffer,1,videoram_size);
  209.         memset(dirtybuffer2,1,matmania_videoram3_size);
  210.     }
  211.  
  212.     /* Update the tiles in the left tile ram bank */
  213.     for (offs = videoram_size - 1;offs >= 0;offs--)
  214.     {
  215.         if (dirtybuffer[offs])
  216.         {
  217.             int sx,sy;
  218.  
  219.  
  220.             dirtybuffer[offs] = 0;
  221.  
  222.             sx = 15 - offs / 32;
  223.             sy = offs % 32;
  224.  
  225.             drawgfx(tmpbitmap,Machine->gfx[1],
  226.                     videoram[offs] + ((colorram[offs] & 0x08) << 5),
  227.                     (colorram[offs] & 0x30) >> 4,
  228.                     0,sy >= 16,    /* flip horizontally tiles on the right half of the bitmap */
  229.                     16*sx,16*sy,
  230.                     0,TRANSPARENCY_NONE,0);
  231.         }
  232.     }
  233.  
  234.     /* Update the tiles in the right tile ram bank */
  235.     for (offs = matmania_videoram3_size - 1;offs >= 0;offs--)
  236.     {
  237.         if (dirtybuffer2[offs])
  238.         {
  239.             int sx,sy;
  240.  
  241.  
  242.             dirtybuffer2[offs] = 0;
  243.  
  244.             sx = 15 - offs / 32;
  245.             sy = offs % 32;
  246.  
  247.             drawgfx(tmpbitmap2,Machine->gfx[1],
  248.                     matmania_videoram3[offs] + ((matmania_colorram3[offs] & 0x08) << 5),
  249.                     (matmania_colorram3[offs] & 0x30) >> 4,
  250.                     0,sy >= 16,    /* flip horizontally tiles on the right half of the bitmap */
  251.                     16*sx,16*sy,
  252.                     0,TRANSPARENCY_NONE,0);
  253.         }
  254.     }
  255.  
  256.  
  257.     /* copy the temporary bitmap to the screen */
  258.     {
  259.         int scrolly;
  260.  
  261.  
  262.         scrolly = -*matmania_scroll;
  263.         if (*matmania_pageselect)
  264.             copyscrollbitmap(bitmap,tmpbitmap2,0,0,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  265.         else
  266.             copyscrollbitmap(bitmap,tmpbitmap,0,0,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  267.     }
  268.  
  269.  
  270.     /* Draw the sprites */
  271.     for (offs = 0;offs < spriteram_size;offs += 4)
  272.     {
  273.         if (spriteram[offs] & 0x01)
  274.         {
  275.             drawgfx(bitmap,Machine->gfx[2],
  276.                     spriteram[offs+1] + ((spriteram[offs] & 0xf0) << 4),
  277.                     (spriteram[offs] & 0x08) >> 3,
  278.                     spriteram[offs] & 0x04,spriteram[offs] & 0x02,
  279.                     239 - spriteram[offs+3],(240 - spriteram[offs+2]) & 0xff,
  280.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  281.         }
  282.     }
  283.  
  284.  
  285.     /* draw the frontmost playfield. They are characters, but draw them as sprites */
  286.     for (offs = matmania_videoram2_size - 1;offs >= 0;offs--)
  287.     {
  288.         int sx,sy;
  289.  
  290.  
  291.         sx = 31 - offs / 32;
  292.         sy = offs % 32;
  293.  
  294.         drawgfx(bitmap,Machine->gfx[0],
  295.                 matmania_videoram2[offs] + 256 * (matmania_colorram2[offs] & 0x07),
  296.                 (matmania_colorram2[offs] & 0x30) >> 4,
  297.                 0,0,
  298.                 8*sx,8*sy,
  299.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  300.     }
  301. }
  302.  
  303. void maniach_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  304. {
  305.     int offs;
  306.  
  307.  
  308.     if (palette_recalc())
  309.     {
  310.         memset(dirtybuffer,1,videoram_size);
  311.         memset(dirtybuffer2,1,matmania_videoram3_size);
  312.     }
  313.  
  314.     /* Update the tiles in the left tile ram bank */
  315.     for (offs = videoram_size - 1;offs >= 0;offs--)
  316.     {
  317.         if (dirtybuffer[offs])
  318.         {
  319.             int sx,sy;
  320.  
  321.  
  322.             dirtybuffer[offs] = 0;
  323.  
  324.             sx = 15 - offs / 32;
  325.             sy = offs % 32;
  326.  
  327.             drawgfx(tmpbitmap,Machine->gfx[1],
  328.                     videoram[offs] + ((colorram[offs] & 0x03) << 8),
  329.                     (colorram[offs] & 0x30) >> 4,
  330.                     0,sy >= 16,    /* flip horizontally tiles on the right half of the bitmap */
  331.                     16*sx,16*sy,
  332.                     0,TRANSPARENCY_NONE,0);
  333.         }
  334.     }
  335.  
  336.     /* Update the tiles in the right tile ram bank */
  337.     for (offs = matmania_videoram3_size - 1;offs >= 0;offs--)
  338.     {
  339.         if (dirtybuffer2[offs])
  340.         {
  341.             int sx,sy;
  342.  
  343.  
  344.             dirtybuffer2[offs] = 0;
  345.  
  346.             sx = 15 - offs / 32;
  347.             sy = offs % 32;
  348.  
  349.             drawgfx(tmpbitmap2,Machine->gfx[1],
  350.                     matmania_videoram3[offs] + ((matmania_colorram3[offs] & 0x03) << 8),
  351.                     (matmania_colorram3[offs] & 0x30) >> 4,
  352.                     0,sy >= 16,    /* flip horizontally tiles on the right half of the bitmap */
  353.                     16*sx,16*sy,
  354.                     0,TRANSPARENCY_NONE,0);
  355.         }
  356.     }
  357.  
  358.  
  359.     /* copy the temporary bitmap to the screen */
  360.     {
  361.         int scrolly;
  362.  
  363.  
  364.         scrolly = -*matmania_scroll;
  365.         if (*matmania_pageselect)
  366.             copyscrollbitmap(bitmap,tmpbitmap2,0,0,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  367.         else
  368.             copyscrollbitmap(bitmap,tmpbitmap,0,0,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  369.     }
  370.  
  371.  
  372.     /* Draw the sprites */
  373.     for (offs = 0;offs < spriteram_size;offs += 4)
  374.     {
  375.         if (spriteram[offs] & 0x01)
  376.         {
  377.             drawgfx(bitmap,Machine->gfx[2],
  378.                     spriteram[offs+1] + ((spriteram[offs] & 0xf0) << 4),
  379.                     (spriteram[offs] & 0x08) >> 3,
  380.                     spriteram[offs] & 0x04,spriteram[offs] & 0x02,
  381.                     239 - spriteram[offs+3],(240 - spriteram[offs+2]) & 0xff,
  382.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  383.         }
  384.     }
  385.  
  386.  
  387.     /* draw the frontmost playfield. They are characters, but draw them as sprites */
  388.     for (offs = matmania_videoram2_size - 1;offs >= 0;offs--)
  389.     {
  390.         int sx,sy;
  391.  
  392.  
  393.         sx = 31 - offs / 32;
  394.         sy = offs % 32;
  395.  
  396.         drawgfx(bitmap,Machine->gfx[0],
  397.                 matmania_videoram2[offs] + 256 * (matmania_colorram2[offs] & 0x07),
  398.                 (matmania_colorram2[offs] & 0x30) >> 4,
  399.                 0,0,
  400.                 8*sx,8*sy,
  401.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  402.     }
  403. }
  404.